<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑限时购表</title>
	<#include "/common/vue_resource.ftl">
</head>
<body>
<div id="app" v-cloak>
	<div class="ui-form">
		<form class="layui-form" @submit.prevent="submitForm()" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">标题<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" v-model="record.title" placeholder="请输入标题" class="layui-input"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">开始日期<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" id="startDate" v-model="record.startDate" placeholder="请输入开始日期" class="layui-input" style="cursor:pointer;" readonly/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">结束日期<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" id="endDate" v-model="record.endDate" placeholder="请输入结束日期" class="layui-input" style="cursor:pointer;" readonly/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">上线/下线</label>
				<div class="layui-input-block" style="padding-top:10px;min-height: 26px;">
					<label class="ui-form-label"><input type="radio" v-model="record.onlineStatus" value="1"/> 上线</label>
					<label class="ui-form-label"><input type="radio" v-model="record.onlineStatus" value="2"/> 下线</label>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</div>
<script>
	var app = new Vue({
		el: '#app',
		data: {
			showTypes: false,
			record : {
				id:'${params.id!}',
				title:'',
				startDate:'',
				endDate:'',
				onlineStatus:'1',
			},
		},
		mounted: function () {
			this.init();
			this.loadData();
		},
		methods: {
			init:function(){
				var that = this;
				laydate.render({elem: '#startDate', type:'date', done:function (value) {
						that.record.startDate = value;
					}});

				laydate.render({elem: '#endDate', type:'date', done:function (value) {
						that.record.endDate = value;
					}});
			},
			loadData: function () {
				if (!'${params.id!}') {
					return;
				}
				var that = this;
				$.http.post('${params.contextPath}/web/smsFlashPromotion/query.json', {id: '${params.id!}'}).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var item = data.data;
					for (var key in  that.record) {
						that.record[key] = item[key];
					}
					that.record.startDate = item.startDateStr || "";
					that.record.endDate = item.endDateStr || "";
				});
			},
			submitForm: function () {
				$.http.post('${params.contextPath}/web/smsFlashPromotion/<#if (params.id)??>modify<#else>save</#if>.json', this.record).then(function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var alt = layer.alert(data.message || "操作成功", function () {
						parent.app.loadData();
						parent.layer.closeAll();
						layer.close(alt);
					});
				});
			},
		}
	});
</script>
</body>

</html>
